from flask import request


class JSONIOStrategy:
    def __init__(self):
        self.car = None

    def catalog_to_json(self, catalog):
        res = list()
        dicti = dict()
        for s in catalog:
            res.append(s.to_json())
        dicti = {"catalog": res}
        # print(dicti)
        return dicti

    def set_car(self, car):
        self.car = car

    def input(self, data):
        return self.car[data]

    def output(self, data):
        pass


class ConsoleIOStrategy:
    def input(self, data):
        return input(data)

    def output(self, data):
        if len(data) == 0:
            raise ValueError
        print(data)


class FlaskIOStrategy:
    def input(self, data):
        return request.form.get(data)

    def output(self, data):
        return data
